package com.doit.doc;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class _01_斗地主 {
    public static void main(String[] args) {
        // 定义一个Map集合用来存储牌号  和 牌
        HashMap<Integer, String> pookerMap = new HashMap<Integer, String>();
        //定义一个List集合用来存储牌号
        ArrayList<Integer> pookerList = new ArrayList<Integer>();

        String[] colors = "♥-♠-♦-♣".split("-");
        String[] nums = "2-A-K-Q-J-10-9-8-7-6-5-4-3".split("-");


        int index = 2;
        for(String num : nums){
            for(String color : colors){
                String thisPooker = color+num;

                //将扑克牌放入Map集合
                pookerMap.put(index, thisPooker);
                //将牌号放入到pookerList集合中
                pookerList.add(index);
                index++;
            }
        }

        //将大王小王添加到集合
        pookerMap.put(0, "大王");
        pookerMap.put(1, "小王");
        pookerList.add(0);
        pookerList.add(1);

        //洗牌
        Collections.shuffle(pookerList);

        //发牌
        ArrayList<Integer> player1 = new ArrayList<Integer>();
        ArrayList<Integer> player2 = new ArrayList<Integer>();
        ArrayList<Integer> player3 = new ArrayList<Integer>();
        ArrayList<Integer> diPai = new ArrayList<Integer>();

        //遍历牌号的集合 判断索引发牌号
        for(int i = 0 ;i < pookerList.size() ;i++){
            Integer pookerNum = pookerList.get(i);
            if(i>=51){
                diPai.add(pookerNum);
        }else if(i % 3 == 0){
            player1.add(pookerNum);
        }else if(i % 3 == 1){
            player2.add(pookerNum);
        }else if(i % 3 == 2){
            player3.add(pookerNum);
        }
    }
    //                排序
    Collections.sort(player1);
    Collections.sort(player2);
    Collections.sort(player3);
    Collections.sort(diPai);

    show("柳岩",player1,pookerMap);
    show("唐嫣",player2,pookerMap);
    show("金莲",player3,pookerMap);
    show("底牌",diPai,pookerMap);

}
    //定义方法 看牌
    public static void show(String name,ArrayList<Integer> player,HashMap<Integer, String> pookerMap ){
        System.out.print(name+":");
        for(Integer pookerNum : player){
            String thisPooker = pookerMap.get(pookerNum);
            System.out.print(thisPooker+" ");
        }
        System.out.println();
    }
}
